﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.Connection;

namespace Ket_noi_toi_VPP_bang_mo_hinh_ba_lop
{
    public partial class DangNhap : Form
    {
        SqlConnection con;
        SqlDataAdapter da=new SqlDataAdapter();

        public DangNhap()
        {
            InitializeComponent();
            con = new SqlConnection(ConnectString.getConnectString());
        }

        private void DangNhap_Load(object sender, EventArgs e)
        {

        }

        private void btReset_Click(object sender, EventArgs e)
        {
            this.txtUser.Clear();
            this.txtPass.Clear();
            this.txtUser.Focus();
        }

        private void btDangNhap_Click(object sender, EventArgs e)
        {
            con.Open();
            DataTable dt = new DataTable();
            SqlCommand cmd = new SqlCommand("Login_Web", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = txtUser.Text;
            cmd.Parameters.Add("@Pass", SqlDbType.VarChar).Value = txtPass.Text;
            da.SelectCommand = cmd;
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read() == false)
                MessageBox.Show("Nhap lai User và Pass");
            else
            {
                int b = dr.GetInt32(dr.GetOrdinal("RoleID"));
                if (b == 1)
                {
                    FormCha fr = new FormCha();
                    this.Hide();
                    fr.ShowDialog();
                }
                if (b == 2)
                {
                    User user = new User();
                    this.Hide();
                    user.ShowDialog();
                }
            }
        }
    }
}
